package com.ququ.syb.payorder.dao.impl;

import com.ququ.syb.common.pojo.PayOrder;
import com.ququ.syb.payorder.dao.PayOrderDao;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class PayOrderDaoImpl extends BaseDaoImpl<PayOrder> implements PayOrderDao {
    @Override
    public PayOrder getPayOrder(String orderno, String appcode) {
        PayOrder payOrder = new PayOrder();
        payOrder.setOutorderno(orderno);
        payOrder.setAppcode(appcode);
        return getEntity(payOrder);
    }

    @Override
    public PayOrder getPayOrder(String tradenum) {
        PayOrder payOrder = new PayOrder();
        payOrder.setTradenum(tradenum);
        return getEntity(payOrder);
    }

    @Override
    public List<PayOrder> listPayOrder(Date beginDate, Date endDate, int currentpage, int pagesize, Integer ordertype, String paychannelid, String accountId, String appcode) {
        Map<String,Object> map = new HashMap<>();
        if(beginDate!=null){
            map.put("beginDate",beginDate);
        }

        if(endDate!=null) {
            map.put("endDate", endDate);
        }
        if(ordertype!=null) {
            map.put("type", ordertype);
        }
        if(!StringUtils.isBlank(paychannelid)) {
            map.put("paychannelid", paychannelid);
        }
        map.put("createaccount",accountId);
        map.put("appcode",appcode);
        map.put("beginDATAIndex",(currentpage-1)*pagesize);
        map.put("pageSize",pagesize);
        return dao.getListByMap("PAYORDER.listPayOrder2",map);
    }

    @Override
    public List<PayOrder> listPayOrder(Map queryMap) {
        return dao.getListByMap("PAYORDER.listPayOrder",queryMap);
    }
}
